php中的資料型態(Data Type)
<?php
$string1 = "Hello world!";
$string2 = 'Hello world!';
$integer = 30;
$float = 3.7;
$boolean1 = true;
$boolean2 = false;
$array = ar("a","b","c");
class learn{
public $L1;
public $L2;
public function __construct($L1, $L2) {
$this->L1 = $L1;
$this->L2 = $L2;
}
public function message() {
return "I am leanring " . $this->L1 . " and " . $this->L2 .".";
}
}
$object = new learn("php","laravel");
echo $object -> message();
$checknull = 'Hello World!';
$checknull = null;
?>
使用var_dump印出的結果會顯示其變數的形態和變數的值,會自動換行。
變數運算
$num1 = 20;
$num2 = 8;
$total1 = $num1 + $num2;
$total2 = $num1 - $num2;
$total3 = $num1 * $num2;
$total4 = $num1 / $num2;
$total5 = $num1 % $num2;
可以使用echo來印出一個或多個字串,但使用時要注意echo不會自動換行
若是要換行的話可以加上."\r\n",注意一定要使用"雙引號",使用'單引號'的話就會被視為字串列印出來,就沒有換行效果了。
例如:echo($total1."\r\n");